Skip to content

Include runtime stderr in error messages#149

Open
arpitjain099 wants to merge 1 commit into
rails:masterfrom
arpitjain099:fix/runtime-error-stderr-142
Open

Include runtime stderr in error messages#149
arpitjain099 wants to merge 1 commit into
rails:masterfrom
arpitjain099:fix/runtime-error-stderr-142

Conversation

@arpitjain099
Copy link
Copy Markdown
Contributor

Summary

Fixes #142. When the external runtime exits non-zero, the diagnostic it writes to stderr (parse errors, stack traces) was being dropped, so ExecJS::RuntimeError carried no useful detail.

5cce03a removed the stderr-into-stdout merge to keep Bun's .env loading noise out of the parsed output (#130). This keeps that property: it captures stderr separately by redirecting the child's stderr to a temp file (a file, not a pipe, so there is no deadlock risk between draining stdout and stderr) and includes it in the error only on the failure path. The success path still reads stdout exactly as before, so #130 stays fixed.

exec_runtime_error now takes an optional stderr argument and is backwards compatible, so the Windows branch (which uses its own 2>&1 > file redirect) is unaffected. The two IO.popen branches that 5cce03a changed (default and JRuby) are the ones updated here.

Test

Adds test_runtime_error_includes_stderr, asserting a non-zero runtime exit surfaces its stderr. Full suite is green locally on MRI 2.6 + Node; the JRuby branch mirrors the same change and relies on CI.

  • Before: the ExecJS::RuntimeError message was empty/uninformative on a runtime parse error.
  • After: the message includes the runtime's stderr (for example the SyntaxError trace).

5cce03a stopped folding stderr into stdout to keep Bun's .env loading
noise out of the parsed output (rails#130). A side effect was that when the
runtime exits non-zero, the diagnostic it writes to stderr (parse errors,
stack traces) is dropped, so the raised ExecJS::RuntimeError carries no
useful detail (rails#142).

Capture stderr separately by redirecting the child's stderr to a temp file
(a file, not a pipe, so there is no risk of a deadlock between draining
stdout and stderr), and include it in the error only on the failure path.
The success path still reads stdout exactly as before, so rails#130 stays fixed.

exec_runtime_error takes an optional stderr argument and is backwards
compatible, so the Windows branch (which uses its own redirect) is
unaffected. The two IO.popen branches that 5cce03a changed (default and
JRuby) are the ones updated here.

Adds a regression test that a non-zero runtime exit surfaces its stderr.

Fixes rails#142

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime stderr is missing from ruby error message

1 participant